<!--
 * @Author: your name
 * @Date: 2022-04-08 15:52:23
 * @LastEditTime: 2023-07-05 11:20:54
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \jk_one-stop_cloud_mobile_v1.0\src\views\dashboard\waiterApply.vue
-->
<template>
  <div class="waitapply">
    <Navbar :appTitle="title" :rtitle="rtitle" :rname="rname" />
    <Search
      :class="GLOBAL.currentEnvironment ? 'topStyle' : ''"
      ref="topSearch"
      class="search"
      placeholder="标题|发起人"
      :isAdd="false"
      :isScreen="true"
      :isType="true"
      @onSearch="onSearch"
      @onScreen="onScreen"
    >
    <template #rightText v-if="titleo=='待我审批'">
      <div style="padding-left:0.1rem" @click="checkedShow=true">批量审批</div>
    </template>
    </Search>
    <search-tag
      ref="SearchTag"
      @resetCategory="resetCategory"
      @getCategory="getCategory"
      v-show="showSearchTag"
    ></search-tag>

    <!--分页列表 -->
    <pageList
    v-if="!checkedShow"
      class="pageClass"
      ref="pageList"
      :operationTxt="operationTxt"
      cancelOperationTxt="拒绝"
      :columns="columns"
      :listUrl="listUrl"
      @getCheckedValue="getCheckedValue"
      @handleList="handleList"
    >
      <div slot="head" slot-scope="{ item }" class="listTitle">
        <span class="title">{{ item.title }}</span>
        <span class="time">{{ formatterDate(item.flowLaunchTime) }}</span>
      </div>
      <div slot="body" slot-scope="{ item }" v-if="item.applyAbstract">
        <div
          class="listRow"
          v-for="(item, index) in getArray(item.applyAbstract)"
          :key="index"
        >
          <span class="key">{{ item.name }}：</span>
          <span class="row">{{ item.value }}</span>
        </div>
      </div>
    </pageList>

    <pageList
     v-else
      class="pageClass checkedShowpage"
      ref="pageList"
      :checkedShow="checkedShow"
      :operationTxt="operationTxt"
      cancelOperationTxt="拒绝"
      :columns="columns"
      :listUrl="listUrl"
      @getCheckedValue="getCheckedValue"
      @handleList="handleList"
    >
      <div slot="head" slot-scope="{ item }" class="listTitle">
        <span class="title">{{ item.title }}</span>
        <span class="time">{{ formatterDate(item.flowLaunchTime) }}</span>
      </div>
      <div slot="body" slot-scope="{ item }" v-if="item.applyAbstract">
        <div
          class="listRow"
          v-for="(item, index) in getArray(item.applyAbstract)"
          :key="index"
        >
          <span class="key">{{ item.name }}：</span>
          <span class="row">{{ item.value }}</span>
        </div>
      </div>
    </pageList>
  </div>
</template>

<script>
import Search from "@/components/search";
import SearchTag from "./SearchTag";
import Navbar from "@/components/navBar/navBar_right";
import TabBar from "@/components/TabBar";
import pageList from "@/components/pageList";
import moment from "moment";

export default {
  name: "carRoomList",
  components: { Navbar, TabBar, pageList, Search,SearchTag },
  data() {
    return {
      title: this.$route.meta.title,
      titleo:this.$route.meta.title,
      applyType: "",
      rtitle: "",
      rname: "", //search
      active: 0,
      tabList: [
        { name: "待排产", value: "1" },
        { name: "待派发至车间", value: "2" },
      ],
      checkedShow: false, //列表是否支持选择
      operationTxt: "同意", //选择按钮名称
      listUrl:
        "/home/homePage/queryTask?queryType=needToExecute&terminalType=mobile", //列表接口
      columns: {
        titleKey: "title", //标题
        // subtitleKey: "description",//副标题
        content: [
          //内容

          // {
          //   name: "发货商品种类",
          //   key: "title",
          // },
          // {
          //   name: "发货总数量",
          //   key: "title",
          // },
        ],
        peopleKey: "launchUserName", //流程发起人
        flowStatusNameKey: "flowStatusName", //流程状态
        // operation: [

        // ],
      },
      showSearchTag: false,
      keywords: "",
      params: {
       
      },
    };
  },
  computed: {},
  mounted() {},
  created() {
    this.applyType = this.$route.query.applyType;
    let queryType = "";
    if (this.applyType == "waiterDeal") {
      this.titleo="待我审批";
      this.title = "待我审批";
      queryType = "needToExecute";
    } else if (this.applyType == "alreadyDeal") {
      this.title = "已审批";
      this.titleo="已审批";
      queryType = "alreadyExecute";
    } else if (this.applyType == "alreadyLaunch") {
      this.title = "已发起";
      this.titleo= "已发起";
      queryType = "createOfMine";
    } else {
      this.title = "我收到的";
      this.titleo= "我收到的";
      queryType = "noticeMe";
    }
    this.listUrl =
      "/home/homePage/queryTask?queryType=" +
      queryType +
      "&terminalType=mobile";
  },
  beforeRouteLeave(to, from, next) {
    let that = this;
    switch (true) {
      case that.showSearchTag :
        that.showSearchTag = false;
        this.title = this.titleo;
        next(false);
        break;
      case that.checkedShow :
        that.checkedShow = false;
        this.title = this.titleo;
        next(false);
        break;
      case !that.showSearchTag:
        next();
        break;
    }
  },
  methods: {
    handleList(id, row, type) {
      console.log(id, row, type, "id:列表id,row:列表对象,type:事件名");
      let detailUrl = "";
      switch (row.type) {
        case "ERP_SHIPPING_APPLY": //申请发货——对应详情
          detailUrl = "/apply/applyDeliverDetail";
          break;
        case "ERP_PURCHASE_TASK_APPLY": //申请采购——对应详情
          detailUrl = "/apply/applyPayDetail";
          break;
        case "ERP_PURCHASE_SIGN_ORDER": //采购合同签收——对应详情
          detailUrl = "/procurementManagement/receiptDetail";
          break;
        case "ERP_PURCHASE_CONTRACT": //新建采购合同——对应详情
          detailUrl = "/procurementManagement/purchaseDetail";
          break;
        case "ERP_SUPPLIER": //新建供应商——对应详情
          detailUrl = "/procurementManagement/supplierDetail";
          break;
        case "MESS_QUALIFIED_INBOUND_APPLY": //合格品申请入库——对应详情
          detailUrl = "/workManagement/qualifiedInput/qualifiedInputDetail";
          break;
        case "MESS_REMEDY_MATERIAL_APPLY": //申请补料——对应详情
          detailUrl = "/workManagement/addMaterialRequisitionDetail";
          break;
        case "MESS_RECEIVE_MATERIAL_APPLY": //申请领料——对应详情
          detailUrl = "/workManagement/materialRequisitionDetail";
          break;
        case "MESS_TASK_REPORT_WORK_APPLY_FOR_QUALITY": //质检报工——对应详情
          detailUrl = "/qualityDetail";
          break;
        case "MESS_TASK_REPORT_WORK_APPLY_FOR_PRODUCT": //生产报工——对应详情
          detailUrl = "/recordDetail";
          break;
        case "MESS_SCRAP_INBOUND_APPLY": //申请报废入库——对应详情
          detailUrl = "/workManagement/executionDetail";
          break;
        case "MESS_RETURN_MATERIAL_APPLY": //申请退料——对应详情
          detailUrl = "/workManagement/returnMaterial/returnMaterialDetail";
          break;
        case "ERP_SALE_CONTRACT": //新建销售合同——对应详情
          detailUrl = "/salesManagement/salesContractDetail";
          break;
        case "ERP_CUSTOMER": //新建客户——对应详情
          detailUrl = "/customerDetail";
          break;
        case "WMS_GOODS": //新建物品——对应详情
          detailUrl =
            "/warehouseManagement/goodsManagement/goodsManagementDetail";
          break;
        case "WMS_WAREHOUSE": //新建仓库——对应详情
          detailUrl = "/warehouseDetail";
          break;
        case "MESS_DEVICE_REPAIR": //故障报修——报修详情
          detailUrl = "/repairDetail";
          break;
        case "WMS_WAREHOUSE_INVENTORY": //库存盘点——盘点单详情
          detailUrl = "/stockCheckDetail";
          break;
          case 'WMS_STOCK_ALLOT': //库存调拨
          detailUrl = '/warehouseManagement/stockAllocation/stockAllocationDetail'
          break
      }
      let paramsObj = {};
      if (row.type == "ERP_SHIPPING_APPLY") {
        paramsObj.applyNo = row.applyNo;
      } else {
        paramsObj.id = row.entityId;
      }
      paramsObj.taskId=row.id;//把任务ID 带到审批页
      // alert(detailUrl)
      // this.$router.push("/commonSearch");
      paramsObj.title=row.title
      paramsObj.applyType = this.applyType;
      // alert("title:"+row.title+"。applyType："+paramsObj.applyType+"。detailUrl："+detailUrl)
      this.$router.push({
        path: detailUrl,
        query: paramsObj,
      });
      // alert("跳转了")
    },
    formatterDate(date) {
      return moment(date).format("YYYY-MM-DD");
    },
    getArray(item) {
      //  console.log(item)
      let arrayList = Object.entries(item);
      let newArrayList = [];
      arrayList.forEach((item) => {
        newArrayList.push({ name: item[0], value: item[1] });
      });
      // console.log(newArrayList);
      return newArrayList;
    },
    onSearch(v) {
      this.keywords = v;
      console.log(this.keywords);
      this.searchQuery();
    },
    onScreen() {
      console.log("筛选");
      this.showSearchTag = true
      this.title = "更多筛选";
     
    },
    resetCategory() {
      // this.showSearchTag = false;
      // this.params = {};
      // this.searchQuery();
    },
    getCategory(v) {
      console.log(v);
      this.showSearchTag = false;
      this.params = Object.assign({}, v);
      if(this.params.applyTimeBegin!=""){
         this.params.applyTimeBegin=this.params.applyTimeBegin+" 00:00:00"
         this.params.applyTimeEnd=this.params.applyTimeEnd+" 23:59:59"
      }
      
      this.title = this.titleo;
      this.searchQuery();
    },
    // 获取选择的列表数据
    getCheckedValue(ids, item, bl) {
      console.log(ids, item, bl);
      if (!ids) {
        this.$toast('请选择数据')
        return
      }
      let approveType = bl == 'cancel' ? 0 : 1
      this.checkedShow = false;
      this.$router.push({ path: '/approval', query: {approveType,taskId:ids} })
    },

    // 加载列表
    getList() {
      // 传1代表从第一条数据开始
      this.$refs.pageList.onLoad(1);
    },
    // 搜索
    searchQuery(v) {
      // 搜索条件
      let queryParam = {
        keyword: this.keywords,
        ...this.params,
      };
      this.$refs.pageList.searchQuery(queryParam);
    },
    // 重置
    searchReset() {
      this.$refs.pageList.searchReset();
    },
    goSearch() {
      this.$router.push({ path: "/carRoomPlaneSearch" });
    },
  },
};
</script>
<style lang="scss" scoped>

.topStyle{
  top: 80px;
}
.waitapply {
  height: 100vh;
  overflow-y: scroll;
  .search {
    width: 100%;
    position: fixed;
    //  height: 150px;
    top: 80px;
    z-index: 999;
    //  margin-bottom:110px;
    //  border: 1p solid red;
  }
  .checkedShowpage{
    /deep/ .van-checkbox__label{
      flex: 1;
    }
    .key {
      padding-right: 0 !important;
    }
  }
  .pageClass {
    margin-top: 104px;
  }
  .listTitle {
    display: flex;
    justify-content: space-between;
    vertical-align: center;
    padding: 10px;
    .title {
      font-size: 32px;
      font-family: PingFang SC;
      font-weight: 500;
      color: #333333;
    }
    .time {
      font-size: 28px;
      font-family: PingFang SC;
      font-weight: 400;
      color: #888888;
    }
  }
  .listRow {
    padding: 10px;
    .key {
      color: #888888;
      display: inline-block;
      padding-right: 20px;
      // border: 1px solid red;
    }
    .value {
      color: #191f25;
      // width: 2.2rem;
      display: block;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }
}
</style>